package com.looookme.shaozhuo.msg;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.looookme.shaozhuo.mb_study.R;

/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class Msg_Toast extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private void initView() {
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        setContentView(linearLayout);

        Button btn_1 = new Button(this);
        btn_1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        btn_1.setText("makeText方法");
        linearLayout.addView(btn_1);

        Button btn_2 = new Button(this);
        btn_2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        btn_2.setText("Toast 构造方法");
        linearLayout.addView(btn_2);

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(Msg_Toast.this, "通过 makeText 方法创建的消息提示框", Toast.LENGTH_SHORT).show();
            }
        });

        btn_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast toast = new Toast(Msg_Toast.this);
                toast.setDuration(Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                LinearLayout ll = new LinearLayout(Msg_Toast.this);
                ImageView iv = new ImageView(Msg_Toast.this);
                iv.setImageResource(R.drawable.ball);
                iv.setPadding(0, 0, 5, 0);
                ll.addView(iv);
                TextView tv = new TextView(Msg_Toast.this);
                tv.setText("通过 Toast构造方法创建的消息提示框");
                ll.addView(tv);
                toast.setView(ll);

                toast.show();
            }
        });
    }
}
